package org.gruposp2p.proyectokarma.service

import org.gruposp2p.proyectokarma.domain.Document;
import org.gruposp2p.proyectokarma.domain.ElectionOption;
import org.codehaus.groovy.grails.web.json.JSONArray;

class ElectionOptionService {
	
	static transactional = true

	def updateDocumentOptions(Document document, JSONArray jsonOptions) {
		def oldOptions = ElectionOption.findAllByDocument(document).collect {oldOption ->
			oldOption.delete()
		}
		jsonOptions.collect { collectedOption ->
			def newOption = new ElectionOption (document:document, content:collectedOption)
			newOption.save()
		}
	}

	
}

